<?php $this->_extends('_layouts/bocib_layout'); ?>

<?php $this->_block('content');?>
<div id="content">
    <h2>流量统计</h2>

    <div>
        <table>
            <tr>
                <td>总点击量：（IP重复计）</td>
                <td>2009/04/27起</td>
                <td><?=THit::find()->getSum('hits');?>次</td>
            </tr>
            <tr>
                <td>总点击量：（IP不重复计）</td>
                <td>2009/04/27起</td>
                <td><?=TIp::find()->getCount('*');?>次</td>
            </tr>

            <tr>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
            </tr>

            <tr>
                <?php $maxDayHits = THit::find()->getMax('hits');?>
                <td>最大单日点击量：（IP重复计）</td>
                <td><?=THit::find('hits = ?', $maxDayHits)->query()->date;?></td>
                <td><?=$maxDayHits;?>次</td>
            </tr>
            <tr>
                <?php $maxWeek = QDB::getConn()->getRow('SELECT week,SUM(hits) AS hits FROM t_hit_by_date GROUP BY week ORDER BY hits DESC');
                ?>
                <td>最大单周访问量：（IP重复计）</td>
                <td><?=$maxWeek['week'];?></td>
                <td><?=$maxWeek['hits'];?>次</td>
            </tr>
            <tr>
                <?php $maxMonth = QDB::getConn()->getRow('SELECT month,SUM(hits) AS hits FROM t_hit_by_date GROUP BY month ORDER BY hits DESC');
                ?>
                <td>最大单月访问量：（IP重复计）</td>
                <td><?=$maxMonth['month'];?></td>
                <td><?=$maxMonth['hits'];?>次</td>
            </tr>
            <tr>
                <?php $distinctMaxDay = QDB::getConn()->getRow('SELECT date,count(ip) as hits FROM t_ip_by_date GROUP BY date ORDER BY hits DESC');
                ?>
                <td>最大单日点击量：（IP不重复计）</td>
                <td><?=$distinctMaxDay['date'];?></td>
                <td><?=$distinctMaxDay['hits'];?>次</td>
            </tr>

            <tr>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
            </tr>

            <tr>
                <?php $maxIPs = QDB::getConn()->getAll('SELECT ip,SUM(hits) AS hits FROM `t_ip_by_date` GROUP BY ip ORDER BY hits DESC LIMIT 0,3');
                ?>
                <td>前三IP访问量</td>
                <td>IP：<?=$maxIPs[0]['ip'];?></td>
                <td>共<?=$maxIPs[0]['hits'];?>次</td>
            </tr>
            <tr>
                <td>&nbsp;</td>
                <td>IP：<?=$maxIPs[1]['ip'];?></td>
                <td>共<?=$maxIPs[1]['hits'];?>次</td>
            </tr>
            <tr>
                <td>&nbsp;</td>
                <td>IP：<?=$maxIPs[2]['ip'];?></td>
                <td>共<?=$maxIPs[2]['hits'];?>次</td>
            </tr>
            
            <tr>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
            </tr>
            
            <tr>
                <?php $maxHours = THour::find()->all()->order('hits DESC')->query();
                ?>
                <td>前三时段访问量</td>
                <td>IP：<?=$maxHours[0]->hour;?></td>
                <td>共<?=$maxHours[0]->hits;?>次</td>
            </tr>
            <tr>
                <td>&nbsp;</td>
                <td>IP：<?=$maxHours[1]->hour;?></td>
                <td>共<?=$maxHours[1]->hits;?>次</td>
            </tr>
            <tr>
                <td>&nbsp;</td>
                <td>IP：<?=$maxHours[2]->hour;?></td>
                <td>共<?=$maxHours[2]->hits;?>次</td>
            </tr>
        </table>

        <h3>浏览器类型统计</h3>
        <table>
            <tr>
                <th>已知浏览器类型</th>
                <th>所占百分比</th>
            </tr>
            <?php $total = TBrowser::find()->getSum('hits');
            foreach(QDB::getConn()->getAll('SELECT browser,sum(hits) as hits FROM t_browser_by_date GROUP BY browser ORDER BY SUM(hits) DESC') as $tbowser) { ?>
            <tr>
                <td><?=$tbowser['browser'];?></td>
                <td><?=$tbowser['hits'];?>(<?=round($tbowser['hits']/$total*100, 2);?>%)</td>
            </tr>
            <?php } ?>
        </table>

        <table>
            <tr>
                <th>未知浏览器类型</th>
                <th>所占百分比</th>
            </tr>
            <?php $total = TUnknownBrowser::find()->getSum('hits');
            foreach(QDB::getConn()->getAll('SELECT browser_identifier,sum(hits) as hits FROM t_unknown_browser_by_date GROUP BY browser_identifier ORDER BY SUM(hits) DESC') as $tunknownbowser) { ?>
            <tr>
                <td><?=$tunknownbowser['browser_identifier'];?></td>
                <td><?=$tunknownbowser['hits'];?>(<?=round($tunknownbowser['hits']/$total*100, 2);?>%)</td>
            </tr>
            <?php } ?>
        </table>
    </div>

    <div>
        <h3>hour时间段统计</h3>
        <table>
            <tr>
                <th>时间段</th>
                <th>所占百分比</th>
            </tr>
            <?php $total = THour::find()->getSum('hits');
            foreach(THour::find()->all()->order('hits DESC')->query() as $thour) { ?>
            <tr>
                <td><?=$thour->hour;?></td>
                <td><?=$thour->hits;?>(<?=round($thour->hits/$total*100, 2);?>%)</td>
            </tr>
            <?php } ?>
        </table>
    </div>

    <div>
        <h3>【前10位】uri统计</h3>
        <table>
            <tr>
                <th>uri</th>
                <th>所占百分比</th>
            </tr>
            <?php $total = TUri::find()->getSum('hits');
            foreach(QDB::getConn()->getAll('SELECT uri,SUM(hits) as hits FROM t_uri_by_date GROUP BY uri ORDER BY SUM(hits) DESC LIMIT 0,15') as $turi) { ?>
            <tr>
                <td><?=$turi['uri'];?></td>
                <td><?=$turi['hits'];?>(<?=round($turi['hits']/$total*100, 2);?>%)</td>
            </tr>
            <?php } ?>
        </table>
    </div>

    <div>
        <h3>【前10位】ip统计</h3>
        <table>
            <tr>
                <th>ip</th>
                <th>所占百分比</th>
            </tr>
            <?php $total = TIp::find()->getSum('hits');
            foreach(QDB::getConn()->getAll('SELECT ip,SUM(hits) as hits FROM t_ip_by_date GROUP BY ip ORDER BY SUM(hits) DESC LIMIT 0,15') as $tip) { ?>
            <tr>
                <td><?=$tip['ip'];?></td>
                <td><?=$tip['hits'];?>(<?=round($tip['hits']/$total*100, 2);?>%)</td>
            </tr>
            <?php } ?>
        </table>
    </div>

    <div>
        <h3>【前10位】referer统计</h3>
        <table>
            <tr>
                <th>referer</th>
                <th>所占百分比</th>
            </tr>
            <?php $total = TReferer::find()->getSum('hits');
            foreach(QDB::getConn()->getAll('SELECT referer,SUM(hits) as hits FROM t_referer_by_date GROUP BY referer ORDER BY SUM(hits) DESC LIMIT 0,15') as $treferer) { ?>
            <tr>
                <td><?=$treferer['referer'];?></td>
                <td><?=$treferer['hits'];?>(<?=round($treferer['hits']/$total*100, 2);?>%)</td>
            </tr>
            <?php } ?>
        </table>
    </div>
</div>
<?php $this->_endblock('content');?>